<?php
include(__DIR__.'/lib/functions.php');
//$module=new module();
//$settings=$module->getSettings(__DIR__);
//print_r($_settings);
//print_r($_json);
//print_r($_GET);
//$_settings is module settings
$page_number=($_GET['page']<=0) ? 1 : $_GET['page'];
$url='http://www.jobbasket.co.uk/api_json.php?term=retail sales,retail manager,branch manager&page='.$page_number;
$json=json_decode(file_get_contents($url),true);
$num_pages=ceil(($json['num_results']/10));
$path=$_GET['_q']."?page=$page_number";

$pagination=pages($page_number,$num_pages,4,$path,$extra='',$class='i-pagination');
$page_number_output=($json['num_results']>=10) ? $page_number : 0;

echo('<div style=""><h2>'.$json['num_results'].' jobs</h2></div>');
echo('<div class="clearfix" style="margin-bottom:2em;"></div>');

$i=0;
echo('<div style="float:left;"><strong>Page '.$page_number_output.' of '.$num_pages.'</strong></div>');
echo('<div style="float:right;">'.$pagination.'</div>');
echo('<div class="clearfix" style="margin-bottom:2em;"></div>');

echo('<div style="float:left;width:728px">');
foreach($json['results'] as $row) {
	
	switch($row['salary']['currency']) {
case "GBP" :
$sc="&pound;";
break;	
case "USD" :
$sc="&#36;";
break;	
case "EUR" :
$sc="&#8364;";
break;	

}
$salary_low=(is_numeric($row['salary']['low'])) ? $sc.number_format($row['salary']['low']) : "Salary ".$row['salary']['low'];
if(is_numeric($row['salary']['low']) && is_numeric($row['salary']['high'])) {
if($row['salary']['high'] > $row['salary']['low']) {
$salary_high=" - $sc".number_format($row['salary']['high']);
}	
} elseif(empty($row['salary']['high'])) {
$salary_high='';	
}
$salary=$salary_low.$salary_high;
$cls=($i%2) ? '' : ' job-alt';
	$href='http://www.jobbasket.co.uk/job/'.$row['seo_title'].'/'.(string)$row['_id']['$id'].'/';
	echo('<div class="job-result'.$cls.'">');
	echo('<div class="job-date">'.date("d-m-y",$row['added']).'</div>');
	echo('<h3 class="job-title"><a class="job-link" href="'.$href.'">'.$row['title'].'</a></h3>');	
	echo('<h4>'.$row['area'].'</h4>');
	echo('<h4>'.$salary.' '.$row['salary']['frequency'].'</h4>');
	echo('<p>'.strip_tags($row['description']).'</p>');
	echo('<p><a class="more-details" href="'.$href.'">More details and application</a></p>');
	echo('</div>');
	if($i%3) {
	echo('<div class="job-result'.$cls.'" style="padding-left:0px;padding-right:0px;">
	<script type="text/javascript"><!--
google_ad_client = "ca-pub-4917036455597458";
/* Retailer Jobs 728 */
google_ad_slot = "6189677635";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
	
	</div>');	
		
	}
	
	
$i++;
}
echo('</div>');
echo('<div style="float:right;width:140px;margin-left:10px;"><h3>Ads by google</h3>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4917036455597458";
/* Retailer Jobs 120 */
google_ad_slot = "8046421657";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4917036455597458";
/* Retailer Jobs 120 */
google_ad_slot = "8046421657";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>');
echo('<div class="clearfix"></div>');
echo('<div style="text-align:right;">'.$pagination.'</div>');
?>
